<!--
 * @Description: location
 * @Author: zzj
 * @Date: 2021-09-15 11:14:34
 * @LastEditors: zzj
 * @LastEditTime: 2021-09-15 11:36:42
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>location</title>
</head>
<body>
    <button id="btn1">百度一下</button>
    <button id="back">后退</button>
    <script>
        var btn1 = document.getElementById("btn1");
        btn1.onclick = function(){
            location.href="http://www.baidu.com";
            //window.location.href="http://www.baidu.com";
            //document.location.href="http://www.baidu.com";
            //location="http://www.baidu.com";
            //window.location.assign("http://www.baidu.com");//会产生历史记录
            //window.location.replace("http://www.baidu.com");//不会产生历史记录
            //location.reload();//默认情况是false,调用缓存：true
        }
        console.log(location.href);  //获取当前的URL
        console.log("协议",location.protocol);
        console.log("服务器的名称和端口号",location.host,location.hostname,location.port);
        console.log("URL的目录和文件名",location.pathname);
        console.log("URL的查询字符串",location.search);


        console.log(history.length);//历史记录数
        back.onclick = function(){
            //history.back();
            history.go(-1);
        }
    </script>
</body>
</html>